<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <script>
    var year = 2022;
        var month = 3;
        var day = 31;

        var num = 1;
        var total = 0;
        while (num < month) {
    var monthnum;

        switch (num) {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    monthnum = 31;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    monthnum = 30;
                    break;
                case 2:
                    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                        //闰年
                        monthnum = 29;
                    } else {
                        // 平年
                        monthnum = 28
                    }
                    break;
                default:
                    console.log("输入错误");
                    break;
            }
            total =total+monthnum;
            num++;
        }
        console.log(total+day);
  </script>
</body>
</html>